<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of StringSupport
 *
 * @author vitor
 */
class StringSupport {

    static private $mensagens;

    static function normaNumero($numero, $totalCaracteres=7) {
        return str_pad($numero, $totalCaracteres, '0', STR_PAD_LEFT);
    }

    static function sorteia8digitos() {
        $numero = rand(0, 9999999);
        return self::normaNumero($numero);
    }

    static function normaliza($string) {
        $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ';
        $b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr';
        $string = utf8_decode($string);
        $string = strtr($string, utf8_decode($a), $b); //substitui letras acentuadas por &quot;normais&quot;
        $string = $nome = str_replace(" ", "-", $string); // troca os espacos por -
        $string = strtolower($string); // passa tudo para minusculo
        $string = utf8_encode($string); //finaliza, gerando uma saída para a funcao
        return $string;
    }

    static function retiraEspacosBrancos($string) {
        $string = isset($string) ? trim($string) : NULL;
        $string = isset($string) ? str_replace(' ', '', $string) : NULL;
        return $string;
    }

    static function corrigeHtml($html) {
        $doc = new DOMDocument();
        $doc->loadHTML('<?xml encoding="UTF-8">' . $html);
        $str = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">', '', $doc->saveHTML());
        $str = str_replace('<?xml encoding="UTF-8">', '', $str);
        $str = str_replace('<html><body>', '', $str);
        $str = str_replace('</body></html>', '', $str);
        return $str;
    }

}

?>
